package com.sa.app.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.sa.app.R;

public class ServiceActivity extends Activity{

    
    private WebView mWebView;
    private String NFCID;
    
    
     public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            setContentView(R.layout.webview);
     
            //asociamos
            mWebView = (WebView) findViewById(R.id.miwebview);
            WebSettings miWebSettings =mWebView.getSettings();
            miWebSettings.setSavePassword(false);
            miWebSettings.setSaveFormData(false);
            miWebSettings.setJavaScriptEnabled(true);
            miWebSettings.setSupportZoom(true);
            
            mWebView.setWebChromeClient(new MyWebChromeClient());
        
            
            NFCID=getIntent().getStringArrayExtra("item")[0];
            	
            	String url=getIntent().getStringArrayExtra("url")[0];
            	if(!url.equals("")){
                    mWebView.loadUrl(url);
                    getActionBar().setHomeButtonEnabled(true);
            	}
     
            //cargo un .html que he situado en la carpeta asset/ del proyecto

        }
     
     
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
 		if (item.getItemId() == android.R.id.home) {
			Intent i = new Intent(getApplicationContext(), ItemActivity.class);
			
			i.setAction("ServiceActivity");
			String[] value= new String[1];
			value[0]=NFCID;
			i.putExtra("item", value);
			startActivity(i);

		}
 		return false;
 	}
             
     /**
      * "alerta" para javascript. Util para depurar javascript.
      */
     private final class MyWebChromeClient extends WebChromeClient {
         @Override
         public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
             result.confirm();
             return true;
         }
     }
}
